home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / C for beginners.adf / source / dec-conv.c < prev    next >
C/C++ Source or Header  |  1978-01-17  |  713b  |  32 lines

  1. /* dec-conv.c 9.4.2 */
  2. void main()
  3. {
  4.   long base, test, help, rest;
  5.   int index;
  6.   char result[260];
  7.  
  8.   printf("Please input number base!\n");
  9.   scanf("%ld", &base);
  10.   printf("Input number in decimal system!");
  11.   scanf("%ld", &test);
  12.   index = 0;
  13.   for(rest = test; rest > 0; rest = rest / base)
  14.    {
  15.     help = rest % base; /* Remainder of Division */
  16.     if(help > 9) /* Letter to substitute */
  17.       result[index] = help + 'A' - 10;
  18.     else
  19.       result[index] = help + '0';
  20.     index = index + 1;
  21.    }
  22.   printf("%ld(10) = ", test);
  23.   index = index - 1; /* last entry is still unused */
  24.   while(index >= 0)
  25.     {
  26.       printf("%c", result[index]);
  27.       index = index - 1;
  28.     }
  29.   printf("(%ld)\n", base);
  30. }
  31.  
  32.